package net.yakiboo.adrums;

import java.util.LinkedList;
import java.util.List;

import android.content.Context;

public class DrumKit {

	private static final float umbral_distancia = 45;
	private List<Drum> drums;
	private Context context;
	private int maxDistance = 23;
	
	public DrumKit(Context c){
		drums = new LinkedList<Drum>();
		this.context = c;
	}
	
	public static DrumKit genDrumKitExample(Context c){
		DrumKit drums = new DrumKit(c);
		drums.addDrum("snare", 0, R.raw.snare);
		drums.addDrum("closed-hihat", 45, R.raw.closedhihat);
		drums.addDrum("midtom", 90, R.raw.midtom);
		drums.addDrum("timbale", 135, R.raw.timbale);
		drums.addDrum("crash", 180, R.raw.crashcymbal);
		return drums;
	}
	
	public List<Drum> getDrums(){
		return drums;
	}
	
	public void addDrum(String name, float position, int sound){
		drums.add(new Drum(this.context, name, position, sound));
	}
	
	public Drum getNearestDrum(float pos){
		float distance = 10000; Drum nearest = null;
		for(Drum d: drums){
			float aux =  Math.abs(pos - d.getPosition());
			if(aux < distance && aux < umbral_distancia){
				distance = aux;
				nearest = d;
			}
		}
		if(distance < maxDistance) return nearest;
		else return null;
	}
	
}
